/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.lang;

import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author VANDH
 */
public class Main {

    public static void swap(AtomicInteger a, AtomicInteger b) {
        int temp = a.get();
        a.set(b.get());
        b.set(temp);
        System.out.println("swap : a = " + a.get() + ", " + " b = " + b.get());
    }

    public static void main(String[] args) {
        // (1) -> (2)
        int i = 10;
        Integer n = Integer.valueOf(i); // static
        System.out.println("i = " + i + ", n = " + n);

        // (2) -> (1)
        int j = n.intValue();   // instance

        // (1) -> (3)
        String s = Integer.toString(j); // static

        // (3) -> (1)
        String number = "123";
        try {
            int k = Integer.parseInt(s);
        } catch (Exception ex) {
            System.out.println("Wrong format");
        }

        // (2) -> (3)
        String s1 = n.toString();

        // (3) -> (2)
        try {
            Integer k = Integer.valueOf(s1);
            k = 10;
            if (n == k) {
                System.out.println(" == ");
            }

            if (n > k) {
                System.out.println(" > ");
            }
        } catch (Exception ex) {
            System.out.println("Wrong format");
        }

        System.out.println(Math.pow(10, 2));

        // [0, 1)
        double r = Math.random();

        // [0, 20)
        r = Math.random() * 20;

        // [10, 20)
        r = Math.random() * 10 + 10;

        // biên lớn - biên nhỏ = n
        // biên nhỏ - 0 = x
        // Math.random() * n + x

        AtomicInteger a = new AtomicInteger(10);
        AtomicInteger b = new AtomicInteger(12);
        swap(a, b);

        System.out.println("a = " + a + ", " + " b = " + b);
    }
}
